import logging
from logging import handlers
loggers = {}


def get_logger(name, file):
    logger = None
    try:
        logger = loggers.get(name)
    except:
        pass
    if logger is None:
        logger = logging.getLogger(name)
        logger.setLevel(logging.INFO)
        handler = handlers.RotatingFileHandler('./logs/' + file, maxBytes=4096000, backupCount=10)

        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        logger.addHandler(handler)

        debug_handler = logging.StreamHandler()
        logger.addHandler(debug_handler)
    return logger
